package com.myapi.ModelPoker;
import java.util.*;



public abstract class CardAnalyser {
	
	public static final int HIGHCARD = 0;
	public static final int PAIR = 1;
	public static final int TWOPAIR = 2;
	public static final int TRIPS = 3;
	public static final int STRAIGHT = 4;
	public static final int FLUSH = 5;
	public static final int FULLHOUSE = 6;
	public static final int FOUROFKIND = 7;
	public static final int STRAIGHTFLUSH = 8;
	
	public CardAnalyser() {

	}	
	
	/**
	 * Template method
	 * Must check hands in order from lowest to highest rank
	 * @param cards
	 * @return
	 */
	public RankedHand analyseCards(Set<Card> cards) {
		RankedHand rankedHand;
		RankedHand tempHand;
		
		tempHand = checkHighCard(cards);
		rankedHand = tempHand;  //default hand is high card, cannot be lower
		tempHand = checkPair(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkTwoPair(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkTrips(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkStraight(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkFlush(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkFullHouse(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkFourOfKind(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		tempHand = checkStraightFlush(cards);
		if(tempHand != null)
			rankedHand = tempHand;
		
		return rankedHand;
	}
	
	public abstract RankedHand checkHighCard(Set<Card> cards);
	public abstract RankedHand checkStraightFlush(Set<Card> cards);
	public abstract RankedHand checkFlush(Set<Card> cards);
	public abstract RankedHand checkStraight(Set<Card> cards);
	public abstract RankedHand checkFullHouse(Set<Card> cards);
	public abstract RankedHand checkPair(Set<Card> cards);
	public abstract RankedHand checkTwoPair(Set<Card> cards);
	public abstract RankedHand checkTrips(Set<Card> cards);
	public abstract RankedHand checkFourOfKind(Set<Card> cards);
}
